//
//  LLClusterBargainViewController.m
//  LoveLove
//
//  Created by 肖兰月 on 2019/4/12.
//  Copyright © 2019 wkf. All rights reserved.
//

#import "LLClusterBargainViewController.h"
#import "LLMallCell.h"
#import "LLShopGoodsModel.h"
#import "LLClusterBargainModel.h"
#import "LLBargainHeader.h"
#import "LLGoodsDetailViewController.h"

@interface LLClusterBargainViewController ()
@property (strong, nonatomic) LLBargainHeader *headerView;
@end

@implementation LLClusterBargainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navTitle = @"组队砍价";
    [self initData];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.tintColor = UIColor.blackColor;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:LLRegularFont(18)}];
    self.navigationController.navigationBar.barTintColor = UIColor.whiteColor;
}

- (void)initData {
//    for (NSInteger i = 0; i < 30; i++) {
//        LLShopGoodsModel *model = LLShopGoodsModel.new;
//        if (i % 3 == 0) {
//            model.title = @"满200-100元优惠券满满200-100元优惠券满满200-100元优惠券满满200-100元优惠券满";
//            model.imgUrl = @"";
//            model.orginalPrice = @"12";
//            model.discountPrice = @"10.5";
//        } else if (i % 3 == 1) {
//            model.title = @"满200-100元优惠券";
//            model.imgUrl = @"";
//            model.orginalPrice = @"17";
//            model.discountPrice = @"761.5";
//        } else {
//            model.title = @"满200-100元优惠券满满200-100元优惠券满满200-100元优惠券满";
//            model.imgUrl = @"";
//            model.orginalPrice = @"12";
//            model.discountPrice = @"6.5";
//        }
//        model.doText = @"去拼团";
//        [self.models addObject:model];
//    }
    [self.tableView reloadData];
    

    LLClusterBargainModel *clusterBargainModel = LLClusterBargainModel.new;
    clusterBargainModel.title = @"满200-100元优惠券满满200-100元优惠券满满200-100元优惠券满";
    clusterBargainModel.imgUrl = @"";
    clusterBargainModel.orginalPrice = @"12";
    clusterBargainModel.discountPrice = @"6.5";
    clusterBargainModel.countStr = @"130";
    clusterBargainModel.bargainFee = @"2";
    clusterBargainModel.bargainNum = @"88";
    clusterBargainModel.bargainedNum = @"78.34";
    clusterBargainModel.leftBargainNum = @"342.1";
    clusterBargainModel.icon = @"";
    clusterBargainModel.nickname = @"Honon";
    clusterBargainModel.noteStr = @"来一起砍价0元拿";
    self.headerView.model = clusterBargainModel;
}

- (void)configTableView {
    [super configTableView];
    self.tableView.height = LLScreenHeight-self.navH;
    [self.tableView registerCellByClassName:@"LLMallCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.tableView.rowHeight = LLScreenWidth < 375 ? 100 : 130;
    CGFloat left = LLScreenWidth < 375 ? 100 : 130;
    self.tableView.separatorInset = UIEdgeInsetsMake(0, left, 0, 0);
    
    _headerView = [[LLBargainHeader alloc] initWithFrame:CGRectMake(0, 0, LLScreenWidth, 430)];
    _headerView.backgroundColor = UIColor.whiteColor;
    self.tableView.tableHeaderView = _headerView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.models.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LLMallCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LLMallCell"];
    cell.model = self.models[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    LLGoodsDetailViewController *vc = LLGoodsDetailViewController.new;
    vc.model = self.models[indexPath.row];
    [self.navigationController pushViewController:vc animated:YES];
}
@end
